<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>博客管理页面</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/themes/icon.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/controls/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	function formatBlogType(val, row) {
		return val.typeName;
	}
	
	function formatTitle(val, row) {
		return "<a target='_blank' href='${pageContext.request.contextPath}/blog/articles/" + row.blogId + ".html' >" + val + "</a>";
	}
	
	
	function searchBlog() {
		$("#dg").datagrid("load", {
			"title" : $("#s_title").val()
		});
	}
	
	function deleteBlog() {
		var selectedRows = $("#dg").datagrid("getSelections");
		if(selectedRows.length == 0) {
			$.messager.alert("系统提示", "请选择要删除的数据!");
			return;
		}
		var idsStr = [];
		for(var i = 0; i < selectedRows.length; i++) {
			idsStr.push(selectedRows[i].blogId);
		}
		var ids = idsStr.join(",");
		$.messager.confirm("系统提示", "您确定要删除选中的<span style='color:red;'>" + selectedRows.length + "</span>条数据吗？", function(r) {
			if(r) {
				$.post("${pageContext.request.contextPath}/admin/blog/delete.do", {
					ids : ids
				}, function(result) {
					if(result.success) {
						$.messager.alert("系统提示", "数据已成功删除!");
						$("#dg").datagrid("reload");
					} else {
						$.messager.alert("系统提示", "数据删除失败!");
					}
				}, "json");
			}
		});
	}
	
	function openBlogModifyTab() {
		var selectedRows = $("#dg").datagrid("getSelections");
		if(selectedRows.length != 1) {
			$.messager.alert("系统提示", "请选择一个要修改的博客");
			return;
		}
		var row = selectedRows[0];
		window.parent.openTab("修改博客", "modifyBlog.jsp?blogId=" + row.blogId, "icon-writeblog");
	}
</script>
</head>
<body style="margin: 1px">
	<table id="dg" title="博客管理" class="easyui-datagrid" fitColumns="true" pagination="true" url="${pageContext.request.contextPath}/admin/blog/listBlog.do" fit="true" toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<th field="blogId" align="center">编号</th>
				<th field="title" align="center" formatter="formatTitle">标题</th>
				<th field="releaseDate" align="center">发布日期</th>
				<th field="blogType" align="center" formatter="formatBlogType">博客类型</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openBlogModifyTab()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:deleteBlog()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			&nbsp;标题&nbsp;<input type="text" id="s_title" size="20" onkeydown="if(event.keyCode==13) searchBlog()"/>
			<a href="javascript:searchBlog()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>		
		</div>
	</div>
</body>
</html>